//
//  LunacherVC.swift
//  HappyToSee
//
//  Created by Wade on 2024/6/18.
//

import ESTabBarController_swift
import Foundation
import SnapKit
import UIKit
import LGSideMenuController

class KYLunacherVC: UIViewController {
    var iconImageView: UIImageView?

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .MainBGColor

        self.setupSubViews()
//        
//        for fontName in UIFont.familyNames {
//            print(fontName)
//        }
    
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            self.pushToTabvc()
        }
    }

    func pushToTabvc() {
        let tabBarController = ESTabBarController()
        if let tabBar = tabBarController.tabBar as? ESTabBar {
            tabBar.itemCustomPositioning = .automatic
            tabBar.backgroundColor = .white
            tabBar.itemPositioning = .centered
        }
        let v0 = KEMainVC()
//        v0.hidesBottomBarWhenPushed = true
        let nav0 = UINavigationController(rootViewController: v0)
        // 3. Create instance of LGSideMenuController with above controllers as root and left.
        let sideMenuController = LGSideMenuController(rootViewController: nav0,
                                                      leftViewController: KYCityListVC(),
                                                      rightViewController: KYCityMenuListVC())

        // 4. Set presentation style by your taste if you don't like the default one.
        sideMenuController.leftViewPresentationStyle = .slideBelowShifted
        sideMenuController.rightViewPresentationStyle = .slideBelowShifted

        // 5. Set width for the left view if you don't like the default one.
        sideMenuController.leftViewWidth = 300.0
        sideMenuController.rightViewWidth = 100.0


//        v1.hidesBottomBarWhenPushed = true
        let v2 = KYRankVC()
//        v2.hidesBottomBarWhenPushed = true
        let nav2 = UINavigationController(rootViewController: v2)
        let v3 = KYSettingVC()
//        v3.hidesBottomBarWhenPushed = true
        let nav3 = UINavigationController(rootViewController: v3)
        nav0.tabBarItem = ESTabBarItem(KYTabContentView(), title: "考拉英语", image: UIImage(named: "ic_tab_main_nor"), selectedImage: UIImage(named: "ic_tab_main_sel"))
        nav2.tabBarItem = ESTabBarItem(KYTabContentView(), title: "排行", image: UIImage(named: "ic_tab_send_nor"), selectedImage: UIImage(named: "ic_tab_send_sel"))
        nav3.tabBarItem = ESTabBarItem(KYTabContentView(), title: "我的", image: UIImage(named: "ic_tab_my_nor"), selectedImage: UIImage(named: "ic_tab_my_sel"))
//        nav0.hidesBottomBarWhenPushed = true;
//        nav1.hidesBottomBarWhenPushed = true;
//        nav2.hidesBottomBarWhenPushed = true;
//        nav3.hidesBottomBarWhenPushed = true;
        
        
        tabBarController.viewControllers = [nav0, nav2, nav3]
        self.view.window?.rootViewController = tabBarController
    }

    func setupSubViews() {
        self.iconImageView = UIImageView()
        self.view.addSubview(self.iconImageView!)
        self.iconImageView?.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.centerY.equalTo(self.view).offset(-50)
            make.size.equalTo(CGSizeMake(146, 163))
        }
        self.iconImageView?.image = UIImage(named: "ic_logo")

        let titleLabel = UILabel()
        self.view.addSubview(titleLabel)
        titleLabel.textColor = .white
        titleLabel.font = .systemFont(ofSize: 14)
        titleLabel.textAlignment = .center
        titleLabel.text = "探索每个不一样的你"
        titleLabel.snp.makeConstraints { make in
            make.width.equalTo(self.view)
            make.centerX.equalTo(self.view)
            make.height.equalTo(30)
            make.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-50)
        }
    }
}
